package com.example.demofdfs.example.lock;

/**
 * 生产者
 * 
 * @author chenyq
 * @email 806512500@qq.com
 * @date 2019年1月5日
 */
public class Producer implements Runnable {

	private Store store;
	
	private int count;
	
	public Producer(Store store) {
		super();
		this.store = store;
	}

	@Override
	public void run() {
		while(true) {
			sleep(500);
			int i = count();
			Commodity c = new Commodity(i, "name-" + i);
			System.out.print(Thread.currentThread().getName() + " : " + c + "  =>>>>  ");
			store.put(c);
		}
	}

	static void sleep(long m) {
		try {
			Thread.sleep(m);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	
	int count() {
		return count++;
	}
}
